package com.example.test.advice.第五章_数组和集合.建议81_非稳定排序推荐使用List;

import org.apache.commons.lang3.builder.CompareToBuilder;

import java.util.ArrayList;
import java.util.SortedSet;
import java.util.TreeSet;

public class Client {

    public static void main(String[] args) {
        testSet3();

    }

    private static void testSet(){
        SortedSet<Person> set = new TreeSet<Person>();
        set.add(new Person(180));
        set.add(new Person(175));
        set.forEach(System.out::println);
    }

    private static void testSet2(){
        SortedSet<Person> set = new TreeSet<Person>();
        set.add(new Person(180));
        set.add(new Person(175));
        set.first().setHeight(185);
        set.forEach(System.out::println);
    }

    private static void testSet3(){
        SortedSet<Person> set = new TreeSet<Person>();
        set.add(new Person(180));
        set.add(new Person(175));
        set.first().setHeight(185);
        set = new TreeSet<>(new ArrayList<>(set));
        set.forEach(System.out::println);
    }

    static class Person implements Comparable<Person>{

        //身高
        private int height;

        public Person(int _age){
            height = _age;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "height=" + height +
                    '}';
        }

        @Override
        public int compareTo(Person o) {
            return new CompareToBuilder().append(height,o.height).toComparison();
        }
    }
}


